package com.fyb.basic.juc.forkjoin;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
 * @Author：MR.FANG
 * @name：ForkJoinTask
 * @Date：2025/7/2 下午2:35
 */
public class ForkJoinTask {
    public static void main(String[] args) {
        // 无锁的空闲栈来管理空闲线程
        ForkJoinPool forkJoinPool = new ForkJoinPool();
        AccumulateTask coutTask = new AccumulateTask(1, 100);
        Future<Integer> future = forkJoinPool.submit(coutTask);
        try {
            Integer sum = future.get(2, TimeUnit.SECONDS);
            System.out.println("最终的计算结果是：sum=" + sum);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

}
